use config::Config;
use serde::Deserialize;


#[derive(Debug, Clone, Default, Deserialize)]
pub struct AppConfig{
    pub server_addr: String,
    pub server_port: u16,
    pub log_level: String,

    pub database_user: String,
    pub database_password: String,
    pub database_host: String,
    pub database_port: u16,
    pub database_name: String,

    pub redis_host: String,
    pub redis_port: u16,
    pub redis_password: String,
    pub redis_db: u8,

}

impl AppConfig {
    pub fn init() -> Self {
        Config::builder()
            .add_source(config::File::with_name("config/app.toml"))
            .add_source(config::Environment::with_prefix("APP"))
            .build()
            .expect("Failed to load configuration")
            .try_deserialize::<AppConfig>()
            .expect("Failed to deserialize configuration")
    }
}